from elasticsearch import Elasticsearch
#忽略警告
import  warnings
warnings.filterwarnings("ignore")

#构建es类
class Estools():

    #初始化函数中,做链接es处理
    def __init__(self):
        self.es = Elasticsearch("http://127.0.0.1:9200")

    #创建索引
    def create_index(self,body):
        result = self.es.indices.create(index="tcdata",body=body)

    #插入文档到索引下
    def insert_data(self,body):
        result = self.es.index(index="tcdata",body=body)



if __name__=="__main__":

    body = {
        "mappings":{
            "properties":{
                "fang_title":{
                    "type":"text",
                    "analyzer":"ik_max_word",
                },
                "fang_price":{
                    "type":"text",
                },
                "fang_href":{
                    "type":"text",
                },
                "fang_address":{
                    "type":"text",
                    "analyzer":"ik_max_word",
                }
            }
        }
    }

    es = Estools()
    es.create_index(body)